<?php
namespace Dianpu\Controller;

class GoodsController extends  Controller {
	protected $db;
	public function __init() {
		$this -> db = new \Dianpu\Model\Goods;
	}

	//菜品列表
	public function index() {
		$data = $this -> db -> getAll();
		View::with('data', $data) -> make();
	}
	
	//添加菜单
	public function add() {
		if (IS_POST) {
			if ($this -> db -> create()) {
				if ($this -> db -> add()) {
					$this -> success('添加成功','index');
				} else {
					$this -> error('服务器忙！请稍候重试');
				}
			} else {
				$this -> error($this -> db -> getError());
			}
		} else {
			$category = Db::table('shop_category')->get();
			
			View::with('category',$category)->make();
		}
	}

}










